package com.atguigu.servicebase.exception;

import com.atguigu.commonutils.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author kabuda
 * @create 2023-04-25 19:28
 */
@Slf4j
@RestControllerAdvice(annotations = {RestController.class, Controller.class})
public class GlobalExceptionHandler {

    @ExceptionHandler(MyException.class)
    public R myException(MyException e){
        log.error("错误日志打印咯：执行自定义异常处理器");
        return R.error().message("执行了自定义异常全局处理器:"+e.getMsg());
    }

    @ExceptionHandler(Exception.class)
    public R ex(Exception e){
        e.printStackTrace();
        return R.error().message("全局异常处理");
    }
}
